<template>
  <view style="padding-bottom: 150upx">
    <view class="pd2030" v-html="agreement"></view>

    <view class="bottom flex-box">
      <view class="btn" @tap="goBack(false)">不同意</view>
      <view v-if="!parner" class="btn yellow flex-box" @tap="goBack(true)">同意协议</view>
      <view
        v-else
        class="btn business-blue flex-box"
        :class="{ deny: !allowGetCode, businessOrange: partnerIncome }"
        @tap="allowGetCode && goBack(true)"
      >
        同意协议
        <view v-if="!allowGetCode" class="">{{ countDown }}S</view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      agreement: null,
      type: 1,
      parner: false,
      countDown: 10,
      allowGetCode: false,
      partnerIncome: false,
    };
  },
  onLoad(e) {
    if (e && e.partnerIncome) {
      this.partnerIncome = e.partnerIncome;
    }
    this.type = e.type;
    if (this.type == 6) {
      uni.setNavigationBarTitle({
        title: '支付协议',
      });
    }
    if (this.type == 3) {
      uni.setNavigationBarTitle({
        title: '提现协议',
      });
    }
    if (this.type == 9) {
      uni.setNavigationBarTitle({
        title: '商科售后卖家服务协议',
      });
    }
    if (this.type == 210) {
      uni.setNavigationBarTitle({
        title: '消费者保障协议',
      });
    }
    if (this.type == 10 || this.type == 11) {
      uni.setNavigationBarTitle({
        title: '商家合伙人计划协议',
      });
    }
    if (this.type == 23) {
      uni.setNavigationBarTitle({
        title: '广州商科账号注销须知',
      });
    }

    if (e && e.parner) {
      this.parner = e.parner;
      if (this.parner) {
        this.timeCountdown();
      }
    }
    this.getAgreement();
  },
  methods: {
    timeCountdown() {
      if (!this.countDown) {
        this.countDown = 10;
        this.allowGetCode = true;
        return;
      }
      this.countDown--;
      setTimeout(() => {
        this.timeCountdown();
      }, 1000);
    },
    goBack(flag = true) {
      if (this.type == 1) {
        uni.setStorageSync('agreeRegister', flag);
        uni.navigateBack();
      }
      if (this.type == 6) {
        uni.setStorageSync('agreeSubmitOrder', flag);
        uni.navigateBack();
        // uni.navigateTo({
        //   url: '../../order/submitOrder/submitOrder',
        // });
      }
      if (this.type == 3) {
        uni.setStorageSync('agreeWidthDraw', flag);
        uni.navigateBack();
      }
      if (this.type == 9 || this.type == 210) {
        uni.setStorageSync('agreeEnter', flag);
        uni.navigateBack();
      }
      if (this.type == 10 || this.type == 11) {
        uni.setStorageSync('agreePartner', flag);
        uni.navigateBack();
      }
      if (this.type == 23) {
        uni.setStorageSync('agreecancallation', flag);
        uni.navigateBack();
      }
    },
    getAgreement() {
      this.apiUrl
        .getRegisterAgreement({
          data: {
            type: this.type,
          },
        })
        .then((res) => {
          res.data.code == 0 ? (this.agreement = res.data.data.content) : '';
        });
    },
  },
};
</script>

<style lang="less" scoped>
.bottom {
  width: 750upx;
  height: 120upx;
  background: rgba(255, 255, 255, 1);
  box-shadow: 0 -2upx 14upx 0 rgba(215, 215, 215, 0.5);
  position: fixed;
  bottom: 0;
  left: 0;
  z-index: 100;
}

.btn {
  width: 260upx;
  border-radius: 10upx;
  border: 1px solid rgba(203, 203, 203, 1);
  color: #656565;
  font-size: 36upx;
  line-height: 80upx;
  text-align: center;
  margin: 0 25upx;

  &.yellow {
    background: #ffd037;
    border-color: #ffd037;
  }
  &.business-blue {
    color: #ffffff;
    background: #4864f6;
    border-color: #4864f6;
  }
  &.businessOrange {
    color: #ffffff;
    background: #e64e2d;
    border-color: #e64e2d;
  }
  &.deny {
    background: rgba(203, 203, 203, 1);
    border-color: rgba(203, 203, 203, 1);
  }
}
</style>
